package ar.com.spsolutions.splibrary.user;

import ar.com.spsolutions.splibrary.user.role.CustomerRole;
import ar.com.spsolutions.splibrary.user.role.LibrarianRole;

public class UserBuilder {
	private User toBuild = new User();

	public UserBuilder withName(final String name) {
		this.getToBuild().setName(name);
		return this;
	}

	public UserBuilder withMail(final String mail) {
		this.getToBuild().setEmail(mail);
		return this;
	}

	public UserBuilder withPassword(final String password) {
		this.getToBuild().setPassword(password);
		return this;
	}

	public UserBuilder asCustomer() {
		this.getToBuild().setRole(new CustomerRole());
		return this;
	}

	public UserBuilder asLibrarian() {
		this.getToBuild().setRole(new LibrarianRole());
		return this;
	}

	public User build() {
		final User temp = this.getToBuild();
		this.setToBuild(new User());
		return temp;
	}

	// ---accesor---
	private User getToBuild() {
		return this.toBuild;
	}

	private void setToBuild(final User toBuild) {
		this.toBuild = toBuild;
	}

	public static User createInstanceForTest() {
		return new UserBuilder().withName("Leandro")//
				.withPassword("mi password secreto :p")//
				.withMail("mimail@hotmial.com")//
				.build();
	}

}
